package com.jyu.hakkatranslation.controller;

import com.jyu.hakkatranslation.service.LogService;
import com.jyu.hakkatranslation.utils.FilesUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

@RestController
@Scope("prototype")
@RequestMapping("/log")
@Slf4j
public class LogController {

    @Autowired
    private LogService logService;

    /**
     * 下载日志接口
     *
     * @param name
     * @param response
     * @throws Exception
     */
    @GetMapping(value = "/download/{name}")
    public void logDownload(@PathVariable String name, HttpServletResponse response) throws Exception {
        logService.logDownload(name, response);
    }
    @RequestMapping("downApp/{fileName}")
    @ResponseBody
    public void Download(@PathVariable String fileName,HttpServletResponse response) {
        String result = FilesUtils.downloadFile(response,fileName);
        log.info("app包下载结果:",result);
    }

}
